/**
 * 请求过滤器
 * @author: xiaoming
 * @date: 16/8/16
 */
(function () {
    var locastorage = window.localStorage;
    angular.module('app')
        .factory('httpRequestInterceptor', httpRequestInterceptor)
        .config(interceptors)
        .run(stateChangeEvents);

    function httpRequestInterceptor($rootScope, $q) {
        return{
            request: function (config) {
                // console.log(config);
                return config;
            },
            response: function (data) {
                // var islogin = locastorage.getItem('isLogined');
                // if(!islogin){
                //     //$rootScope.$broadcast('unlogin', true);
                //     return $q.reject(data);
                // }

                return data;
            }
        }
    }

    // 拦截器
    interceptors.$inject = ['$httpProvider'];
    function interceptors($httpProvider) {
        $httpProvider.interceptors.push('httpRequestInterceptor');
    }

    stateChangeEvents.$inject = ['$rootScope', '$state'];
    function stateChangeEvents($rootScope, $state) {
        $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options) {
            
        })
    }
})();
